package dyq.example.com;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;
import androidx.recyclerview.widget.RecyclerView;

public class adapter extends RecyclerView.Adapter<adapter.MyViewHolder> {

    private List<String> mList = new ArrayList<>();
    private Context context;//官方运行的环境参数
    //private View inflater;


    //adapter()构造函数
    public adapter(Context context, List<String>list) {
       this.mList = list;
       this.context = context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemview = LayoutInflater.from(context).inflate(R.layout.item,parent,false);
        return new MyViewHolder(itemview);
        //inflater = LayoutInflater.from(context).inflate(R.layout.tab01,parent,false);
        //MyViewHolder myviewholder = new MyViewHolder(inflater);
        //return myviewholder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder myviewholder, int position) {
        //adapter中有一个list(String列表值)
        myviewholder. textView .setText(mList.get(position));
    }

    @Override
    public int getItemCount() {
        //返回dataset即list的长度
        return mList == null ? 0 : mList.size();
    }


    public static class MyViewHolder extends RecyclerView.ViewHolder{
        TextView  textView ;
        public MyViewHolder(View itemView) {
            super(itemView);
            //viewholder里有一个行视图，现在往里面穿一个文本值（textView）
            textView = itemView.findViewById(R.id.textView);
        }
    }

}
